﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
using SharpGen.Enums;

namespace SharpGen.Templates
{
    [Serializable]
    public class StringReplacementCollection : CollectionBase, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public StringReplacementCollection()
        {

        }

        public StringReplacement this[int index]
        {
            get { return base.List[index] as StringReplacement; }
            set { base.List[index] = value; }
        }

        public List<StringReplacement> ToList()
        {
            return base.List.Cast<StringReplacement>().ToList();
        }

        public string ReplaceText(string text, StringReplacementType replaceType, SqlObjectType objectType)
        {
            string retText = text;
            foreach (StringReplacement sr in base.List)
            {
                retText = sr.ReplaceText(retText, replaceType, objectType);
            }
            return retText;
        }

        public int Add(StringReplacement item)
        {
            return base.List.Add(item);
        }

        public void Remove(StringReplacement item)
        {
            base.List.Remove(item);
        }

        protected override void OnClearComplete()
        {
            base.OnClearComplete();
            OnPropertyChanged("Clear");
        }

        protected override void OnInsertComplete(int index, object value)
        {
            base.OnInsertComplete(index, value);
            OnPropertyChanged("Insert");
        }

        protected override void OnRemoveComplete(int index, object value)
        {
            base.OnRemoveComplete(index, value);
            OnPropertyChanged("Remove");
        }

        protected override void OnSetComplete(int index, object oldValue, object newValue)
        {
            base.OnSetComplete(index, oldValue, newValue);
            OnPropertyChanged("Set");
        }

        protected void OnPropertyChanged(string info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }
}
